<template>
  <div>
    <!-- 设置服药时间 -->
    <el-dialog v-model="dialogVisible" title="设置服药时间" width="500" :before-close="handleClose">
      <span>
        <el-form
          ref="ruleFormRef"
          style="max-width: 600px"
          :model="ruleForm"
          label-width="auto"
          class="demo-ruleForm"
          status-icon
        >
          <el-form-item label="停止服药时间">
            <el-date-picker
              v-model="ruleForm.endDate"
              style="width: 100%"
              type="datetime"
              value-format="YYYY-MM-DD"
            />
          </el-form-item>
        </el-form>
      </span>
      <template #footer>
        <div class="dialog-footer">
          <el-button @click="handleClose">取消</el-button>
          <el-button type="primary" @click="submit">确定</el-button>
        </div>
      </template>
    </el-dialog>
  </div>
</template>

<script setup lang="ts">
import { defineEmits, defineProps, reactive } from "vue";
import { UpdateEndDateParams } from "@/api/medicalcare/medicinelogs/type";
import { ElMessage, FormInstance } from "element-plus";
import { UpdateEndDate } from "@/api/medicalcare/medicinelogs/medicinelogs";

const dialogVisible = ref(true);
const props = defineProps({
  currentId: Number,
});

//修改参数
const ruleForm = reactive<UpdateEndDateParams>({
  id: props.currentId ? props.currentId : 0,
  endDate: "",
});

const emit = defineEmits(["close"]);

const submit = async () => {
  if (!ruleForm.endDate) {
    ElMessage.error("请选择结束时间");
    return;
  }

  await UpdateEndDate(ruleForm);
  ElMessage({
    message: "添加成功",
    type: "success",
  });
  emit("close", true);
};

//关闭
const handleClose = () => {
  emit("close");
};
</script>

<style scoped></style>
